local dabai = fk.CreateSkill{
  name = "xiaobai__dabai&"
}

Fk:loadTranslationTable{
  ["xiaobai__dabai&"] = "大白",
  [":xiaobai__dabai&"] = "你可以将一张“小白杯”武将牌当对应武将牌上技能中的牌名的牌使用",
}

local XBB = require "packages.xiaobai.util"

dabai:addEffect("viewas", {
  mute = true,
  pattern = ".", 
  interaction = function (self, player)
    local cardnames = {}
    local cards = table.map(player:getCardIds("h"), Util.Id2CardMapper)
    for _, card in ipairs(cards) do
      if XBB.startsWithEndsWith(card.name) then
        table.insertTableIfNeed(cardnames, card:getTableMark("xiaobai__tianxiadaba_card"))
      end
    end
    local able_names = player:getViewAsCardNames("xiaobai__dabai&", cardnames, player:getCardIds("h"))
    return UI.CardNameBox{
      choices = able_names,
      all_choices = cardnames,
    }
  end,
  card_filter = function (self, player, to_select, selected, selected_targets)
    return self.interaction.data and #selected == 0 and table.contains(Fk:getCardById(to_select):getTableMark("xiaobai__tianxiadaba_card"), self.interaction.data)
  end,
  view_as = function (self, player, cards)
    if (not self.interaction.data) or #cards == 0 then
      return
    end
    local card = Fk:cloneCard(self.interaction.data, Card.Spade, 9)
    card:addSubcards(cards)
    return card
  end,
  enabled_at_response = function (self, player, isResponse)
    return table.find(player:getCardIds("h"), function (card)
      return XBB.startsWithEndsWith(Fk:getCardById(card).name) and #Fk:getCardById(card):getTableMark("xiaobai__tianxiadaba_card") > 0
    end)
  end,
  enabled_at_play = function (self, player)
    return table.find(player:getCardIds("h"), function (card)
      return XBB.startsWithEndsWith(Fk:getCardById(card).name) and #Fk:getCardById(card):getTableMark("xiaobai__tianxiadaba_card") > 0
    end)
  end,
})

return dabai